// import { get_image } from '../utils'

const ProductCategory = {
  _description: '产品类别',
  _name: 'product.category',
  _fields: {
    name: { type: 'char', string: '名称' },
    complete_name: { type: 'char', string: '全名', compute: true },
    parent_id: {
      type: 'many2one',
      string: '上级类别'
      // fields: { name: null, parent_path: null },
      // filter: ({ record, options }) => {
      //   // console.log('PartnerCategory,', record, options)
      //   // parent_id 不能选自己, 不能选儿孙
      //   return options.filter(item => {
      //     const parent_path = item.object.parent_path
      //       .split('/')
      //       .map(item => Number(item))

      //     return item.value !== record.id && !parent_path.includes(record.id)
      //   })
      // }
    }
  },

  metadata: {}
}

const ProductTemplate = {
  _description: '产品',
  _name: 'product.template',
  _fields: {
    name: { type: 'char', string: '名称' },
    sale_ok: { type: 'boolean', string: '销售' },
    purchase_ok: { type: 'boolean', string: '采购' },
    type: { type: 'selection', string: '产品类型' },
    categ_id: { type: 'many2one', string: '产品类别' },
    default_code: { type: 'char', string: '产品编码' },
    barcode: { type: 'char', string: '条形码' },
    list_price: { type: 'float', string: '销售价格' },
    standard_price: { type: 'float', string: '成本' },

    description: { type: 'text', string: '内部备注' },
    invoice_policy: { type: 'selection', string: '开票策略' },
    description_sale: { type: 'text', string: '销售说明' },
    seller_ids: {
      type: 'one2many',
      relation: 'product.supplierinfo',
      string: '供应商'
    },
    description_purchase: { type: 'text', string: '采购说明' }
  },
  metadata: {
    propForView: {
      fields: {
        name: null,
        sale_ok: null,
        purchase_ok: null
      },

      notebook: {
        default: 'general_information',
        pages: [
          {
            name: 'general_information',
            label: '基本信息',
            fields: {
              type: null,
              categ_id: null,
              default_code: null,
              barcode: null,
              list_price: null,
              standard_price: null,
              description: null
            }
          },
          {
            name: 'sales',
            label: '销售',
            fields: {
              invoice_policy: null,
              description_sale: null
            }
          },
          {
            name: 'purchase',
            label: '采购',
            fields: {
              seller_ids: null,
              description_purchase: null
            }
          },
          {
            name: 'inventory',
            label: '库存',
            fields: {}
          }
        ]
      }
    }
  }
}

const ProductSale = {
  _description: '产品',
  _inherit: 'product.template',
  _name: 'ProductSale',

  metadata: {
    filter: ['sell_or_purchase.filter_to_sell'],

    propForList: {
      searchs: {
        sell_or_purchase: {
          string: '销售或采购',
          filters: {
            filter_to_sell: {
              string: '销售',
              domain: [['sale_ok', '=', true]]
            },
            filter_to_purchase: {
              string: '采购',
              domain: [['purchase_ok', '=', true]]
            }
          }
        },
        type: {
          string: '产品或服务',
          filters: {
            consumable: {
              string: '产品',
              domain: [['type', 'in', ['consu', 'product']]]
            },
            services: { string: '服务', domain: [['type', '=', 'service']] }
          }
        }
      }
    }
  }
}

const Models = {
  'product.category': ProductCategory,
  'product.template': ProductTemplate,
  ProductSale: ProductSale
}

export default Models
